package com.wct;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

public class MyHandler extends ChannelHandlerAdapter {  
	private int UNCONNECT_NUM_S = 0;
    @Override  
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt)  
            throws Exception {  
    	
        if (evt instanceof IdleStateEvent) {  
            IdleStateEvent e = (IdleStateEvent) evt;  
            if (e.state() == IdleState.ALL_IDLE) {   
                System.out.println("超时");  
                UNCONNECT_NUM_S++;
            }
            if(UNCONNECT_NUM_S > 2) {  
                System.err.println("client connect status is disconnect.");  
                ctx.close();  
                //此处当重启次数达到2次之后，关闭此链接后，清除服务端相关的记录信息  
            }  
        }
        
        
    }  
}  
